package com.itheima.listviewsample.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.util.ArrayMap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.itheima.listviewsample.ListViewGridViewAdapter;
import com.itheima.listviewsample.MyAdapter;
import com.itheima.listviewsample.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * A simple {@link Fragment} subclass.
 */
public class ListViewGrideViewFragment extends Fragment {
    private ListView listview;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_list_view1, container, false);
    }


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        listview = (ListView) view.findViewById(R.id.listview);
        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                view.setSelected(true);
            }
        });
        init();
    }

    private void init() {

        Map<String, List<String>> data=new ArrayMap<>();


        List<String> imageUrl = new ArrayList<>();
        imageUrl.add("https://b4-q.mafengwo.net/s7/M00/5F/71/wKgB6lQH-NOAGAPGABaQOIFArE029.jpeg?imageView2%2F2%2Fw%2F680%2Fq%2F90");
        imageUrl.add("https://file106.mafengwo.net/s7/M00/5F/C6/wKgB6lQH-SOAS_AhAC_-ZiEVWpE28.jpeg?imageView2%2F2%2Fw%2F680%2Fq%2F90");
        imageUrl.add("https://file106.mafengwo.net/s7/M00/60/91/wKgB6lQH-d-AcOF7ADFSNi0tp6c77.jpeg?imageView2%2F2%2Fw%2F680%2Fq%2F90");
        imageUrl.add("http://f.hiphotos.baidu.com/image/pic/item/5ab5c9ea15ce36d358d27ee43ef33a87e850b114.jpg");
        imageUrl.add("http://e.hiphotos.baidu.com/image/pic/item/72f082025aafa40f6f6d3209af64034f79f019be.jpg");
        imageUrl.add("http://c.hiphotos.baidu.com/image/pic/item/359b033b5bb5c9ea9f59ff37d139b6003bf3b3b8.jpg");
        imageUrl.add("http://c.hiphotos.baidu.com/image/pic/item/ac4bd11373f0820278976deb4ffbfbedaa641bd8.jpg");
        imageUrl.add("http://g.hiphotos.baidu.com/image/pic/item/6159252dd42a2834b200cadf5fb5c9ea14cebf44.jpg");


        for (int i = 0; i < 5; i++) {
            data.put("Hello Heima" + i,imageUrl );
        }


        listview.setAdapter(new ListViewGridViewAdapter(getContext(),data));
    }
}
